home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-10-13 | 12.5 KB | 350 lines | [TEXT/MPS ] |
- (******************************************************************************
- *
- * Apple Macintosh Developer Technical Support
- *
- * Interfaces for the utility routines
- *
- * Program: Sample 3.0
- * File: SampleUtilties.p - Pascal implementation
- *
- * by: Matt Deatherage
- *
- * Copyright © 1988-1993 Apple Computer, Inc.
- * All rights reserved.
- *
- *******************************************************************************
- *
- * This file contains many utility routines, ones which don't really fit
- * in with the rest of the organization but are still useful, necessary
- * and proper. Some of these routines are from Macintosh Technical Notes
- * or Inside Macintosh, and others are just useful encapsulations of
- * techniques we needed within Sample.
- *
- ******************************************************************************)
-
- UNIT SampleUtilities;
-
- INTERFACE
-
- (*******************************************************************************
- * Used Units
- *******************************************************************************)
-
- USES Errors, Resources, Packages, ToolUtils, PrintTraps, AppleTalk, Processes,
- PPCToolbox, EPPC, Notification, AppleEvents, Features;
-
- (*******************************************************************************
- * Constants
- *******************************************************************************)
-
- CONST
- kMissingAppNameStr = - 16396; { 'STR ' with our application name in it }
-
- rActionAlertBase = 5000; { base resource ID for close/quit Alert }
- kClosing = 1; { string to use when closing }
- kQuitting = 2; { string to use when quitting }
-
-
- { Buttons in the "Save changes to document?" Alert }
-
- kSave = 1; { "Save" }
- kCancel = 2; { "Cancel" }
- kDontSave = 3; { "Don’t save" }
-
- { Resource IDs for alerts for errors for HandleFileError }
-
- rIOError = 2001; { Got an I/O error on a file }
- rFileAlreadyOpen = 2002; { That file's already open so you
- can't open it again }
- rNoPermission = 2003; { You don't have permission for that file }
- rSomeWeirdError = 2004; { An uncommon error happened }
- rDiskWriteProt = 2005; { the disk is write-protected }
- rFileVersionInconsistent = 2006;{ the internal file version is later than
- what we recognize }
- rFileDiskLocked = 2007; { can't open with write permission }
- rSaveChanges = 2008; { ask if we should save changes before
- closing or quitting }
- rCantWriteFile = 2009; { Couldn't write the file to disk }
-
- rUntitledStrings = 1003; { 'STR#' resource with untitled strings }
- kUntitledWithSpaceString = 1; { "untitled " }
- kUntitledNoSpaceString = 2; { "untitled" }
-
- { key code constants for the ClassifyKey routine }
-
- kEnterKey = 3;
- kDeleteKey = 8;
- kTabKey = 9;
- kReturnKey = 13;
- kEscapeKey = 27;
- kLeftArrowKey = 28;
- kRightArrowKey = 29;
- kUpArrowKey = 30;
- kDownArrowKey = 31;
- kPeriodKey = 46;
-
- { bit numbers for the flags in ClassifyKey }
-
- kDigitKeyBit = 0;
- kLetterKeyBit = 1;
- kHexDigitKeyBit = 2;
- kEditKeyBit = 3;
- kNonControlKeyBit = 4;
- kCommandKeyBit = 5;
- kCancelKeyBit = 6;
- kAcceptKeyBit = 7;
-
- { Masks for bits in the flags in ClassifyKey }
-
- kDigitKey = 1;
- kLetterKey = 2;
- kHexDigitKey = 4;
- kEditKey = 8;
- kNonControlKey = 16;
- kCommandKey = 32;
- kCancelKey = 64;
- kAcceptKey = 128;
-
- (*******************************************************************************
- * Types
- *******************************************************************************)
-
- TYPE
-
- (*******************************************************************************
- * Types
- *
- * FileLikeSpec is a record declared the same as an FSSpec, but they're not
- * equivalent records, meaning you have to use a little effort to pass
- * FileLikeSpec to an FSSpec File Manager routine. This is as it should be,
- * because we're using this as a convenient storage facility, not necessarily
- * as something created with MakeFSSpec, and it's important to not pass
- * hand-made FSSpec records to the File Manager. This largely comes in
- * handy for changing FSSpec records we get from the system into a format we
- * can use instead of the other way around.
- ********************************************************************************)
-
- FileLikeSpec = RECORD
- vRefNum: INTEGER;
- parID: LONGINT;
- name: Str63;
- END;
- FileLikeSpecPtr = ^FileLikeSpec;
-
- (*******************************************************************************
- * Global variables maintained by this unit
- *******************************************************************************)
-
- VAR
- gUntitledWindowCount: LONGINT; { count of windows we've opened this
- session }
-
- (*******************************************************************************
- * Types -- we declare an EventRecord pointer for efficiency
- *******************************************************************************)
-
- TYPE
-
- EventRecordPtr = ^EventRecord;
-
- (*******************************************************************************
- *
- * IsDAWindow - returns TRUE if the window passed is a desk accessory window.
- * Only needed for 6.0.7 systems not using MultiFinder.
- *
- *******************************************************************************)
-
- FUNCTION IsDAWindow(window: WindowPtr): BOOLEAN;
-
- (*******************************************************************************
- *
- * IsAppWindow - returns TRUE if the window passed is a window that belongs
- * to our application
- *
- *******************************************************************************)
-
- FUNCTION IsAppWindow(window: WindowPtr): BOOLEAN;
-
- (*******************************************************************************
- *
- * ClassifyKey - returns information about a keystroke
- *
- * This routine takes an event record and returns a two-byte INTEGER full of
- * bit flags (defined above) telling what kind of keypress it was -- an
- * editing key, command key, digit key, etc. Very useful for filter procedures
- * in dialogs.
- *
- *******************************************************************************)
-
- FUNCTION ClassifyKey(theEventPtr: EventRecordPtr): INTEGER;
-
- (*******************************************************************************
- *
- * OKToInteract - checks to see if user interaction is allowed
- *
- * This routine checks AEInteractWithUser to see if it's OK to talk to the user
- * about something, and prepares to do user interaction if it is by setting
- * the arrow cursor.
- *
- *******************************************************************************)
-
- FUNCTION OKToInteract: BOOLEAN;
-
- (*******************************************************************************
- *
- * MustInteract - requires user interaction
- *
- * This routine calls AEInteractWithUser with no timeout, never returning until
- * it's ok to interact with the user.
- *
- *******************************************************************************)
-
- PROCEDURE MustInteract;
-
- (*******************************************************************************
- *
- * AlertUser - tell the user about something
- *
- * This routine takes a resource ID of an 'ALRT' resource, and presents the
- * user with that Alert, ignoring what Button is pressed. Handy for telling
- * the user things, but not for getting any input back.
- *
- *******************************************************************************)
-
- PROCEDURE AlertUser(alertNum: INTEGER);
-
- (*******************************************************************************
- *
- * AskUser - ask the user about something
- *
- * This routine takes a resource ID of an 'ALRT' resource, and presents the
- * user with that Alert, returning TRUE if the user picked the default button
- * (item #1).
- *
- *******************************************************************************)
-
- FUNCTION AskUser(alertNum: INTEGER): BOOLEAN;
-
- (*******************************************************************************
- *
- * DoPromptSave - find out if the user wants to save a file
- *
- * This routine presents an alert of the form "Save the <application name>
- * document <theName> before <closing/quitting>? Don't Save/cancel/Save".
- * The action is either kClosing or kQuitting, and the return value is
- * either kSave, kCancel or kDontSave. This routine calls MustInteract
- * because no default answer to this question is really safe.
- *
- *******************************************************************************)
-
- FUNCTION DoPromptSave(theName: Str63; theAction: INTEGER): INTEGER;
-
- (*******************************************************************************
- *
- * HandleFileError - tell the user about file errors
- *
- * HandleFileError alerts users to common file errors and also gives a generic
- * alert for things we weren't actually prepared to handle. The error is the
- * first parameter, and the window we're working with is the second so the
- * dialogs can say things like "You can't save the document <windTitle> because
- * the disk is write-protected, bozo." Or maybe slightly more polite.
- *
- *******************************************************************************)
-
- PROCEDURE HandleFileError(myErr: OSErr; windTitle: Str255);
-
- (*******************************************************************************
- *
- * CheckRequiredAEParms - see if we processed an Apple Event correctly
- *
- * This routine looks for the keyMissingKeywordAttr in an Apple Event record,
- * which is only present if we did _not_ process all the required parameters.
- * If it's not present, things are fine and it returns noErr. Otherwise,
- * there was a missing parameter and it returns errAEEventNotHandled.
- * Note that this is really a pointer to an AppleEvent record -- Pascal passes
- * all parameters bigger than four bytes by reference. I'd make this more
- * explicit by using an "AppleEventPtr" type except one isn't defined, and
- * defining it here probably isn't that useful.
- *
- *******************************************************************************)
-
- FUNCTION CheckRequiredAEParms(theAppleEvent: AppleEvent): OSErr;
-
- (*******************************************************************************
- *
- * CreateWindowTitle - make a title for a new window
- *
- * This routine creates a string suitable for window titles such as "untitled",
- * "untitled 2", etc. as specified by Macintosh Human Interface Guidelines.
- * You pass an existing string and CreateWindowTitle replaces it with your
- * new title.
- *
- *******************************************************************************)
-
- PROCEDURE CreateWindowTitle(VAR theString: Str63);
-
- (*******************************************************************************
- *
- * DoCopyResource - copy a resource from one file to another
- *
- * This routine is from Inside Macintosh: Macintosh Toolbox Essentials. It
- * copies a resource of type theType and ID theID from resource file source
- * to resource file dest, returning any error.
- *
- *******************************************************************************)
-
- FUNCTION DoCopyResource(theType: ResType; theID, source, dest: INTEGER): OSErr;
-
- (*******************************************************************************
- *
- * DeviceLoopSim - simulate DeviceLoop when it's not present
- *
- * This routine is from issue #10 of _develop_, the Apple Technical Journal.
- * It's Forrest Tanaka's routine to simulate the DeviceLoop trap for machines
- * that have color QuickDraw but not DeviceLoop (in other words, System 6
- * machines).
- *
- *******************************************************************************)
-
- PROCEDURE DeviceLoopSim(drawingRgn: RgnHandle; drawingProc: Ptr;
- userData: LONGINT; flags: LONGINT);
-
- (*******************************************************************************
- *
- * NewPrJobMerge - merge job-specific parameters of two print records
- *
- * This routine is from Macintosh Technical Note "Fun with PrJobMerge" and
- * works around a bug in LaserWriter 7.x that makes the real PrJobMerge
- * sometimes damage your original print record.
- *
- *******************************************************************************)
-
- PROCEDURE NewPrJobMerge(hPrintSrc, hPrintDst: THPrint);
-
- (*******************************************************************************
- *
- * GetNextWindow - find the next window in the window list
- *
- * This routine returns the window immediately below the specified window.
- *
- *******************************************************************************)
-
- FUNCTION GetNextWindow(theWindow: WindowPtr): WindowPtr;
-
- (*******************************************************************************
- *
- * UpdateAllAppWindows - completely draw all of our document windows
- *
- * UpdateAllAppWindows goes through all windows we have and makes sure that
- * none of them have any pending updates.
- *
- *******************************************************************************)
-
- PROCEDURE UpdateAllAppWindows;
-
- IMPLEMENTATION
-
- {$I SampleUtilities.inc1.p}
-
- END.
-